package com.umeng.analytics.pro;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.concurrent.atomic.AtomicInteger;

class u {
    private AtomicInteger a;
    private AtomicInteger b;
    private static u c;
    private static SQLiteOpenHelper d;
    private SQLiteDatabase e;

    u() {

        this.a = new AtomicInteger();
        this.b = new AtomicInteger();
    }

    public static u a(Context arg2) {
        u v0_1;
        Class v1 = u.class;
        synchronized (v1) {
            if (u.c == null) {
                u.b(arg2);
            }

            v0_1 = u.c;
        }
        return v0_1;
    }

    public SQLiteDatabase a() {
        SQLiteDatabase v0_1;
        synchronized (this) {
            if (this.a.incrementAndGet() == 1) {
                this.e = u.d.getWritableDatabase();
            }

            v0_1 = this.e;
        }
        return v0_1;
    }

    private static void b(Context arg2) {
        Class v1 = u.class;
        synchronized (v1) {
            if (u.c == null) {
                u.c = new u();
                u.d = t.a(arg2);
            }
        }
    }

    public void b() {
        synchronized (this) {
            if (this.a.decrementAndGet() == 0) {
                this.e.close();
            }

            if (this.b.decrementAndGet() == 0) {
                this.e.close();
            }
        }
    }
}

